package view;

import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

import com.algorithms.Algorithm2;
import com.algorithms.Recomendable;

//VS4E -- DO NOT REMOVE THIS LINE!
public class TopTweetsSelector extends JDialog {

	private static final long serialVersionUID = 1L;
	private JComboBox jComboBox0;
	private JLabel jLabel0;
	private JButton jButton0;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public TopTweetsSelector() {
		initComponents();
	}

	public TopTweetsSelector(Frame parent) {
		super(parent);
		initComponents();
	}

	public TopTweetsSelector(Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public TopTweetsSelector(Frame parent, String title) {
		super(parent, title);
		initComponents();
	}

	public TopTweetsSelector(Frame parent, String title, boolean modal) {
		super(parent, title, modal);
		initComponents();
	}

	public TopTweetsSelector(Frame parent, String title, boolean modal,
			GraphicsConfiguration arg) {
		super(parent, title, modal, arg);
		initComponents();
	}

	public TopTweetsSelector(Dialog parent) {
		super(parent);
		initComponents();
	}

	public TopTweetsSelector(Dialog parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public TopTweetsSelector(Dialog parent, String title) {
		super(parent, title);
		initComponents();
	}

	public TopTweetsSelector(Dialog parent, String title, boolean modal) {
		super(parent, title, modal);
		initComponents();
	}

	public TopTweetsSelector(Dialog parent, String title, boolean modal,
			GraphicsConfiguration arg) {
		super(parent, title, modal, arg);
		initComponents();
	}

	public TopTweetsSelector(Window parent) {
		super(parent);
		initComponents();
	}

	public TopTweetsSelector(Window parent, ModalityType modalityType) {
		super(parent, modalityType);
		initComponents();
	}

	public TopTweetsSelector(Window parent, String title) {
		super(parent, title);
		initComponents();
	}

	public TopTweetsSelector(Window parent, String title,
			ModalityType modalityType) {
		super(parent, title, modalityType);
		initComponents();
	}

	public TopTweetsSelector(Window parent, String title,
			ModalityType modalityType, GraphicsConfiguration arg) {
		super(parent, title, modalityType, arg);
		initComponents();
	}

	private void initComponents() {
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setBackground(Color.white);
		setForeground(Color.black);
		setLayout(new GroupLayout());
		add(getJButton0(), new Constraints(new Leading(179, 10, 10), new Leading(86, 10, 10)));
		add(getJLabel0(), new Constraints(new Leading(45, 10, 10), new Leading(40, 12, 12)));
		add(getJComboBox0(), new Constraints(new Leading(239, 10, 10), new Leading(36, 12, 12)));
		setSize(406, 148);
	}

	private JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("ok!");
			jButton0.addMouseListener(new MouseAdapter() {

				public void mouseClicked(MouseEvent event) {
					jButton0MouseMouseClicked(event);
				}
			});
		}
		return jButton0;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setText("Elija un usuario top tweets");
		}
		return jLabel0;
	}

	private JComboBox getJComboBox0() {
		if (jComboBox0 == null) {
			jComboBox0 = new JComboBox();
			jComboBox0.setModel(new DefaultComboBoxModel(new Object[] {
					"toptweets", "toptweets_es" }));
			jComboBox0.setDoubleBuffered(false);
			jComboBox0.setBorder(null);

		}
		return jComboBox0;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}

	/**
	 * Main entry of the class. Note: This class is only created so that you can
	 * easily preview the result at runtime. It is not expected to be managed by
	 * the designer. You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				TopTweetsSelector dialog = new TopTweetsSelector();
				dialog
						.setDefaultCloseOperation(TopTweetsSelector.DISPOSE_ON_CLOSE);
				dialog.setTitle("TopTweetsSelector");
				dialog.setLocationRelativeTo(null);
				dialog.getContentPane().setPreferredSize(dialog.getSize());
				dialog.pack();
				dialog.setVisible(true);
			}
		});
	}

	private void jButton0MouseMouseClicked(MouseEvent event) {

		String user = (String) jComboBox0.getSelectedItem();

		Recomendable a2 = new Algorithm2(user);

		RunningDialog r = new RunningDialog(((ResultsFrame) getParent()), a2);
		r.setLocationRelativeTo(this);
		r.setTitle("Paciencia");
		r.setVisible(true);

		this.dispose();
	}
}